package top.healthylife.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import top.healthylife.domain.Order;

import java.util.List;
import java.util.Map;

/**
 * @author GaoZeXi
 */
public interface OrderMapper {

    /**根据
     * 预约条件查询预约信息
     * @param order
     * @return
     */
    @Select("select * from t_order where member_id = #{memberId} and orderDate = " +
            "#{orderDate} and setmeal_id = #{setmealId}")
    List<Order> findByCondition(Order order);

    /**
     * 预约成功,添加预约信息
     * @param order
     */
    @Insert("insert into t_order values (null,#{memberId},#{orderDate},#{orderType}," +
            "#{orderStatus},#{setmealId})")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void add(Order order);

    /**
     * 根据预约id查询预约信息，包括体检人信息、套餐信息
     * @param id  预约id
     * @return
     */
    @Select("select m.name member ,s.name setmeal,o.orderDate orderDate,o.orderType " +
            " orderType from t_order o,t_member m,t_setmeal s  where " +
            "o.member_id=m.id and o.setmeal_id =s.id and o.id =#{id}")
    Map findById4Detail(Integer id);
}
